using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Editors;
using DevExpress.XtraEditors;
using System.Windows.Forms;

namespace Ascent.QiPei.Module.Win.Controllers
{
    public partial class EnterMoveNextControlController : ViewController
    {
        public EnterMoveNextControlController()
        {
            InitializeComponent();
            RegisterActions(components);
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            base.View.ControlsCreated += new EventHandler(this.View_ControlsCreated);
        }

        private void View_ControlsCreated(object sender, EventArgs e)
        {
            foreach (ViewItem item in ((DetailView)base.View).Items)
            {
                if (typeof(BaseEdit).IsInstanceOfType(item.Control))
                {
                    var edit = item.Control as BaseEdit;
                    edit.EnterMoveNextControl = true;
                    edit.Enter += edit_Enter;
                }
            }
        }

        void edit_Enter(object sender, EventArgs e)
        {
            var edit = sender as BaseEdit;
            if (edit.Enabled == false)
            {
                edit.SendKey(new KeyEventArgs(Keys.Tab));
            }
        }
    }
}
